﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace CMS
{
    public class DbHelper
    {
        private static readonly string connter = "server=.; database=CMS; uid=sa;pwd=123456;";
/// <summary>
/// 获取数据
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
        public static DataTable GetData(string sql)
        {
            SqlDataAdapter adapter = new SqlDataAdapter(sql,connter);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
        }
        /// <summary>
        /// 增加删除修改
        /// </summary>
        /// <param name="sql"></param>
        public static void AddAndDeleteAddUpdate(string sql)
        {
            SqlConnection connection = new SqlConnection(connter);
            SqlCommand command = new SqlCommand(sql, connection);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }

    }
}